package com.cdxy.dmr.repository;

import com.cdxy.dmr.dataObject.SmsTemplateDO;
import com.cdxy.dmr.mapper.SmsTemplateMapper;
import com.cdxy.model.dto.base.mybatis.BaseRepository;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Repository;

/**
 * <p>
 * 短信模板表 服务实现类
 * </p>
 *
 * @author autoGenCode
 * @since 2020-03-05
 */
@Repository
@CacheConfig(cacheNames = "sms_template")
public class SmsTemplateRepository extends BaseRepository<SmsTemplateMapper, SmsTemplateDO> {

    /**
     *  查询权值最大的短信模板
     *
     * @return
     */
    @Cacheable(key = "'getOrderByWeightDesc'", unless = "#result == null ")
    public SmsTemplateDO getOrderByWeightDesc() {
        return this.baseMapper.selectOne(this.queryWrapper()
                .orderByDesc(SmsTemplateDO::getWeight)
                .last("LIMIT 1"));
    }

}
